var SHOPCAR = function() 
{
	var o = {};
	
	o.run = function()
	{
		o.check();
	
	}
	<!--购物车页面默认设置-->
	o.check = function(){
		//默认全选
		$('#selectall').attr('checked',true);
		$("input[name='items[]']").attr('checked',true);
		//合计计算
		var tsum = 0;
		var count = 0;
		var collid = document.getElementById('selectall');
		var coll = document.getElementsByName('items[]');
		
		if (collid.checked){
			for(var i = 0; i < coll.length; i++){
				tp = coll[i].value;
				count++;
				tsum = parseFloat(tsum) + parseFloat(tp);
			}	
		}
		var sum = tsum;
		$('#itemscount').html(count);
		$('#Total').html(sum);
		
	}
	
	<!--全选反选-->
	o.allcheck = function(){
		
		var collid = document.getElementById('selectall');
		var coll = document.getElementsByName('items[]');
		var tsum = 0;
		var count = 0;
		if (collid.checked == true){
			for(var i = 0; i < coll.length; i++){
				coll[i].checked = true;
				tp = coll[i].value;
				count++;
				tsum = parseFloat(tsum) + parseFloat(tp);
			}	
			var sum = $('#Total').html();
			sum = tsum;
			$('#itemscount').html(count);
			$('#Total').html(sum);
		}
		else{
			for(var i = 0; i < coll.length; i++){
				coll[i].checked = false;
			}
			sum = tsum;
			$('#itemscount').html(count);
			$('#Total').html(sum);
		}
	}
	
	<!--判断是否勾选影响总额并记录勾选状态-->
	o.checkprice = function(obj){
		//记录勾选状态传到数据库
		var click_id = $(obj).next().val();
		var status = $(obj).siblings('.statuscheck').val();
		
		var tsum = 0;
		var coll = document.getElementsByName('items[]');
		var count = 0;
		for(var i = 0; i < coll.length; i++){
			if (coll[i].checked){
				$('#selectall').attr('checked',false);
				status = 0 //勾选为0
				var tp = coll[i].value;
				count++;
				tsum = parseFloat(tsum) + parseFloat(tp);
			}
			else{
				status = 1 //未勾选为1
			}
		}	
		
		var sum = $('#Total').html();
		sum = tsum;
		$('#itemscount').html(count);
		$('#Total').html(sum);	
	}
	
	<!--勾选数量改变金额-->
	o.cartnumcheck = function(obj){
		var cart_num = $(obj).parents('.sl').find(".text_box").val();
		var button = $(obj).val();
		var price = $(obj).parents('.td-amount').prev('.td-price').find('.price_now').html();
		var ware_id = $(obj).parents('.td-amount').next('.td-sum').find('.kepid').val();
		var cart_list = $(obj).parents('.td-amount').next('.td-sum').find('.sku_list').val();
		//判断加减改变金额
		if( button == '-'){
			cart_num--;
			var total_price = parseFloat(price) * parseFloat(cart_num);
			$(obj).parents('.td-amount').next('.td-sum').find('.item_totalprice').html(total_price);
		}
		if( button == '+'){
			cart_num++;
			total_price = parseFloat(price) * parseFloat(cart_num);
			$(obj).parents('.td-amount').next('.td-sum').find('.item_totalprice').html(total_price);
		}

		//ajax传后台更新金额
		$.post('/Api/pay/totalprice' , { ware_id:ware_id , cart_list:cart_list , cart_num:cart_num , total_price:total_price} ,function(ret){
			if( ret.status == true){
				window.location.href="";
				return;
			}
		});
		
	}
	
	<!--检查登录进入支付页面-->
	o.logincheck = function(obj){
		var payprice = $(obj).parents('.btn-area').prev('.price-sum').find('#Total').html();
		
		$.get('/Api/pay/logincheck' , {payprice:payprice} , function(ret){
			if( ret.status == true){
				var order_id = ret.data.order_id;
				window.location.href="/home/pay/pay?order_id="+order_id;
			}
			else{
				alert(ret.data);
				window.location.href="/home/login/login";
			}
		});
	}
	
	<!--显示总价-->
	o.payindex = function(){
		var tsum = 0;
		var count = 0;
		var coll = document.getElementsByName('ttp');
		
		for(var i = 0; i < coll.length; i++){
			tp = coll[i].value;
			tsum = parseFloat(tsum) + parseFloat(tp);
		}	
		
		var sum = tsum;
		$('#lastpay').html(sum);
		$('.pay-sum').html(sum);
	}
	
	<!--支付页面根据数量改变金额-->
	o.paycheck = function(obj){
		var cart_num = $(obj).parents('.sl').find(".text_box").val();
		var button = $(obj).val();
		var price = $(obj).parents('.td-amount').prev('.pay-phone').find('.price_now').html();
		var ware_id = $(obj).parents('.td-amount').next('.td-sum').find('.kepid').val();
		var cart_list = $(obj).parents('.td-amount').next('.td-sum').find('.sku_list').val();

		//判断加减改变金额
		if( button == '-'){
			cart_num--;
			var total_price = parseFloat(price) * parseFloat(cart_num);
			$(obj).parents('.td-amount').next('.td-sum').find('.item_totalprice').html(total_price);
		}
		if( button == '+'){
			cart_num++;
			total_price = parseFloat(price) * parseFloat(cart_num);
			$(obj).parents('.td-amount').next('.td-sum').find('.item_totalprice').html(total_price);
		}

		//ajax传后台更新金额
		$.post('/Api/pay/totalprice' , { order_id:order_id , ware_id:ware_id , cart_list:cart_list , cart_num:cart_num , total_price:total_price} ,function(ret){
			if( ret.status == true){
				window.location.href=window.location.href;
			}
		});
		
	}
	<!--设置默认地址-->
	o.paydecheck = function(){
		$('.user-addresslist').each(function(){
			var moren = $(this).find('.hres1').val();
			if( moren == 1 ){
				$(this).addClass('defaultAddr');
				$(this).find('.deftip').removeClass('hidden');
				$(this).find('.lockmoren').addClass('hidden');	
			}
		});
	}
	
	<!--提交-->
	o.paybtn = function(){
		var coll = document.getElementsByName('tips');
		tips = coll[0].value;
		var payprice = $('#lastpay').html();
		
		$.post('/Api/pay/paybtn' , { order_id:order_id ,tips:tips , payprice:payprice} , function(ret){
			if( ret.status == true){
				alert(ret.data);
				window.location.href="/home/pay/success?order_id="+order_id;
			}
			else{
				alert(ret.data);
			}
		});
	}
	
	return o;
}();




